package org.jeecg.demo.wx.event;

import org.jeecg.demo.wx.entity.EScheduledUser;
import org.jeecg.demo.wx.enumeration.ScheduleStatusEnum;
import org.jeecg.demo.wx.service.IEScheduledUserService;
import org.jeecg.demo.wx.util.UpdateCountUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 功能描述
 *
 * @author: zgq
 * @date: 2024年03月10日 15:27
 */
@Component
public class CompleteEventListener implements ApplicationListener<CompleteEvent> {
    @Autowired
    private UpdateCountUtil updateCountUtil;
    @Autowired
    private IEScheduledUserService iEScheduledUserService;

    @Override
    public void onApplicationEvent(CompleteEvent event) {
        String userId = event.getUserId();
        updateCountUtil.plus(userId, null, ScheduleStatusEnum.FINISHED);
        updateCountUtil.minus(userId, ScheduleStatusEnum.UNDO);
        String scheduleId = event.getScheduleId();
        iEScheduledUserService.lambdaUpdate()
                .set(EScheduledUser::getStatus, ScheduleStatusEnum.FINISHED.getDesc())
                .eq(EScheduledUser::getUserId, userId).eq(EScheduledUser::getScheduledId, scheduleId)
                .update();
    }
}
